home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / CPX / MODEM.TC / PORTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  6.6 KB  |  283 lines

  1. /* PORTS.C
  2.  *==========================================================================
  3.  * DATE: March 9, 1990
  4.  * DESCRIPTION: MODEM CPX
  5.  *        Reading and writing to the 4 serial ports
  6.  */
  7.  
  8.  
  9.  
  10. /* INCLUDE FILES 
  11.  *==========================================================================
  12.  */
  13. #include <sys\gemskel.h>
  14. #include <tos.h>
  15.  
  16. #include "struct.h"
  17. #include "modem2.h"
  18.  
  19.  
  20. /* PROTOTYPES
  21.  *==========================================================================
  22.  */
  23. void    Write_Port( int cur_port, BUFFER *store );
  24. void    Read_Port( int cur_port, BUFFER *store );
  25. void    Set_Rsconf( int cur_port );
  26.  
  27. void    Set_BaudRate( int baudrate );
  28. int    Get_BaudRate( BUFFER *store );
  29.  
  30. void    Set_FlowControl( int flow );
  31. int    Get_FlowControl( BUFFER *store );
  32.  
  33. void    Set_UCR( int parity, int stop, int bits );
  34. int    Get_UCR( void );
  35.  
  36. int    Get_Parity( int SData );
  37. int    Get_StopBits( int SData );
  38. int    Get_BitsChar( int SData );
  39.  
  40.  
  41. /* DEFINES
  42.  *==========================================================================
  43.  */    
  44.  
  45.  
  46.  
  47. /* EXTERNALS
  48.  *==========================================================================
  49.  */
  50.  
  51.  
  52.  
  53. /* GLOBALS
  54.  *==========================================================================
  55.  */
  56.  
  57.  
  58. /* FUNCTIONS
  59.  *==========================================================================
  60.  */
  61.  
  62.  
  63.  
  64.  
  65. /* Write_Port()
  66.  *==========================================================================
  67.  * Set the current active serial port with the current data in 
  68.  * the data structure. NOTE: The port has already been mapped in.
  69.  * IN: MDATA *modem:   The modem data structure array
  70.  *     int   cur_port: The current active serial port - 0 - 3
  71.  *     BUFFER *store:  Pointer to the 64byte buffer in the node
  72.  *               This however, has already been incremented
  73.  *               to the proper location based on cur_port.
  74.  *               store  =   for 0
  75.  *               store++=   for port 1
  76.  *            etc...
  77.  */
  78. void
  79. Write_Port( int port, BUFFER *store )
  80. {
  81.      Set_Active_Port( port );
  82.      store->cur_baud    = Modem.modem[ port ].cur_baud;
  83.      store->cur_flow    = Modem.modem[ port ].cur_flow;
  84.      Set_Rsconf( port );
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. /* Read_Port()
  92.  *==========================================================================
  93.  * Read the current active port data INTO the modem structure
  94.  * Note: the port has already been mapped in.
  95.  * IN: cur_port: The active current port index
  96.  *     store:    Pointer to the current port node buffer
  97.  */
  98. void
  99. Read_Port( int port, BUFFER *store )
  100. {
  101.   int UCR_Data;
  102.   
  103.   Set_Active_Port( port );
  104.   Modem.modem[ port ].cur_baud  = Get_BaudRate( store );
  105.   Modem.modem[ port ].cur_flow  = Get_FlowControl( store );
  106.  
  107.   Set_BaudRate( Modem.modem[ port ].cur_baud );
  108.   Set_FlowControl( Modem.modem[ port ].cur_flow );
  109.   
  110.   UCR_Data = Get_UCR();
  111.   Modem.modem[ port ].cur_parity = Get_Parity( UCR_Data ); 
  112.   Modem.modem[ port ].cur_stop   = Get_StopBits( UCR_Data );
  113.   Modem.modem[ port ].cur_bits   = Get_BitsChar( UCR_Data );
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. /* Set_Rsconf()
  121.  *==========================================================================
  122.  * Set the current active serial port mapped in with new data
  123.  * The port has already been mapped.
  124.  */
  125. void
  126. Set_Rsconf( int port )
  127. {
  128.     Set_BaudRate( Modem.modem[ port ].cur_baud );
  129.     Set_FlowControl( Modem.modem[ port ].cur_flow );
  130.     Set_UCR( Modem.modem[ port ].cur_parity,
  131.              Modem.modem[ port ].cur_stop,
  132.              Modem.modem[ port ].cur_bits );    
  133. }
  134.  
  135.  
  136.  
  137. /* Set_BaudRate()
  138.  *==========================================================================
  139.  * Set the Current Baud Rate 
  140.  */
  141. void
  142. Set_BaudRate( int baudrate )
  143. {
  144.     Rsconf( baudrate, -1, -1, -1, -1, -1 );
  145. }
  146.  
  147.  
  148.  
  149.  
  150. /* Get_BaudRate()
  151.  *==========================================================================
  152.  * Return the current baud rate.
  153.  * On Tos 1.4 or greater, we can get the actual baud rate.
  154.  * Otherwise, we return what we think it is in the 64 byte node buffe
  155.  */
  156. int
  157. Get_BaudRate( BUFFER *store )
  158. {
  159.    if( Check_OS() )
  160.        return( (int)Rsconf( -2, -1, -1, -1, -1, -1 ) );
  161.    else
  162.        return( store->cur_baud );
  163. }
  164.  
  165.  
  166.  
  167.  
  168. /* Set_FlowControl()
  169.  *==========================================================================
  170.  * Set the Flow Control for the current active serial port
  171.  */
  172. void
  173. Set_FlowControl( int flow )
  174. {
  175.    Rsconf( -1, flow, -1, -1, -1, -1 );
  176. }
  177.  
  178.  
  179.  
  180.  
  181. /* Get_FlowControl()
  182.  *==========================================================================
  183.  * Get the current flow control from the buffer.
  184.  * NOTE: we can't read the flow control from the hardware, therefore
  185.  * we must get it from the buffer instead.
  186.  */
  187. int
  188. Get_FlowControl( BUFFER *store )
  189. {
  190.    return( store->cur_flow );
  191. }
  192.  
  193.  
  194.  
  195. /* Set_UCR()
  196.  *==========================================================================
  197.  * Set the UCR in the current active Serial port
  198.  */
  199. void
  200. Set_UCR( int parity, int stop, int bits )
  201. {
  202.     int SData;
  203.     
  204.     SData = Get_UCR();    
  205.     /* Preserve bits 0 and 7, clear out bits 1 thru 6 */
  206.     SData &= 0x81;
  207.  
  208.     /* Add 1 to parity to correspond to actual settings 
  209.      *    we want        they want
  210.      *      0        0    No Parity
  211.      *      0        1    No Parity
  212.      *      1        2    Odd Parity
  213.      *      2        3    Even Parity
  214.      * Just remember to subtract 1 later when reading rsconf...
  215.      */
  216.     SData |= ( ( ( parity + 1 ) << 1 ) & 0x06 );
  217.     SData |= ( ( stop << 3 ) & 0x18 );
  218.     SData |= ( ( bits << 5 ) & 0x60 );
  219.     Rsconf( -1, -1, SData, -1, -1, -1 );
  220. }
  221.  
  222.  
  223.  
  224.  
  225. /* Get_UCR()
  226.  *==========================================================================
  227.  * Get the current UCR from the current active serial port
  228.  */
  229. int
  230. Get_UCR( void )
  231. {
  232.    long RData;
  233.    int  SData;
  234.    
  235.    RData = Rsconf( -1, -1, -1, -1, -1, -1 );
  236.    SData = ( int )( ( RData >> 24 ) & 0xff );
  237.    return( SData );
  238. }
  239.  
  240.  
  241.  
  242.  
  243. /* Get_Parity()
  244.  *==========================================================================
  245.  * Get the current parity from the current active serial port
  246.  */
  247. int
  248. Get_Parity( int SData )
  249. {
  250.    int parity;
  251.    
  252.    parity = (int)( ( SData >> 1 ) & 0x03 );
  253.    if( parity ) parity -= 1;
  254.    return( parity );
  255. }
  256.  
  257.  
  258.  
  259. /* Get_StopBits()
  260.  *==========================================================================
  261.  * Get the current stop bits from the active serial port
  262.  */
  263. int
  264. Get_StopBits( int SData )
  265. {
  266.      return( ( SData >> 3 ) & 0x03 );
  267. }
  268.  
  269.  
  270.  
  271. /* Get_BitsChar()
  272.  *==========================================================================
  273.  * Get the current bits per character from the active serial port
  274.  */
  275. int
  276. Get_BitsChar( int SData )
  277. {
  278.    return( ( SData >> 5 ) & 0x03 ); 
  279. }
  280.  
  281.  
  282.  
  283.